def swap(t1,t2):
    return t2,t1

class Solution:
    def nextPermutation(self, nums) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        length = len(nums)
        te = 0
        for i in range(length-2,-1,-1):
            if nums[i] < nums[i+1]:
                for j in range(length-1,i,-1):
                    if nums[j] > nums[i]:
                        nums[i],nums[j] = swap(nums[i],nums[j])
                        break
                nums[i+1:] = sorted(nums[i+1:])
                te = 1
                break
        if te == 0:
            nums.sort()
#         print(nums)

# if __name__ == "__main__":
#     ss = [3,2,1]
#     s = Solution()
#     s.nextPermutation(ss)

